home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / latex209 / contrib / diagramf / diagramf.sty < prev    next >
Text File  |  1993-01-11  |  8KB  |  223 lines

  1. %%% ====================================================================
  2. %%%  @LaTeX-style-file{
  3. %%%     author          = "Alan Jeffrey",
  4. %%%     version         = "1.1",
  5. %%%     date            = "02 June 1992",
  6. %%%     time            = "13:39:09 BST",
  7. %%%     filename        = "diagramf.sty",
  8. %%%     address         = "School of Cognitive and Computing Sciences
  9. %%%                        University of Sussex
  10. %%%                        Brighton BN1 9QH
  11. %%%                        UK",
  12. %%%     telephone       = "+44 273 606755 x 3238",
  13. %%%     FAX             = "+44 273 678188",
  14. %%%     checksum        = "50716 222 988 7967",
  15. %%%     email           = "alanje@cogs.sussex.ac.uk",
  16. %%%     codetable       = "ISO/ASCII",
  17. %%%     keywords        = "diagrams, metafont",
  18. %%%     supported       = "yes",
  19. %%%     abstract        = "This is a LaTeX style file for importing
  20. %%%                        diagrams drawn in metafont.",
  21. %%%     docstring       = "This is part of the diagramf package which
  22. %%%                        interfaces TeX and metafont.  It is
  23. %%%                        described in diagramf.tex.
  24. %%%
  25. %%%                        Copyright 1992 Alan Jeffrey.
  26. %%%
  27. %%%                        The checksum field above contains a CRC-16
  28. %%%                        checksum as the first value, followed by the
  29. %%%                        equivalent of the standard UNIX wc (word
  30. %%%                        count) utility output of lines, words, and
  31. %%%                        characters.  This is produced by Robert
  32. %%%                        Solovay's checksum utility.",
  33. %%%     package         = "diagramf",
  34. %%%     dependencies    = "diagramf.mf",
  35. %%%     maintainer      = "Jeremy Gibbons",
  36. %%%     address-maintainer = "Department of Computer Science
  37. %%%                        University of Aukland
  38. %%%                        Private Bag
  39. %%%                        Aukland
  40. %%%                        New Zealand",
  41. %%%     email-maintainer = "jeremy@cs.aukuni.ac.nz",
  42. %%%  }
  43. %%% ====================================================================
  44. %%%
  45. %%% 25 Oct 1990, v1.0: Released version 1.0.
  46. %%%
  47. %%% 29 Oct 1990, v1.01: Discovered I'd put \everylabel into the
  48. %%% diagram rather than the label.  Silly me.
  49. %%%
  50. %%% 30 Oct 1990, v1.02: \diagramf now uses \copy to put down the
  51. %%% diagram rather than \box, so diagrams can be reused.
  52. %%%
  53. %%% 2 Jun 1992, v1.1: Added standard headers.
  54.  
  55. % This style allows you to use diagrams generated in metafont with TeX
  56. % lables, such as those produced with diagramf.mf.
  57. %
  58. % To use the diagrams generated by example.mf, you say
  59. %
  60. %    \diagramfile{example}
  61. %
  62. % which loads all the diagrams and stores them in boxes.  You can then
  63. % use a diagram by saying (for example)
  64. %
  65. %    \diagramf{2}
  66. %
  67. % which gets you the second diagram.  When you load in another
  68. % file of diagrams, you over-write the previous diagrams.
  69. %
  70. % All the definitions made by \diagramfile are purely local, so if you
  71. % say
  72. %
  73. %    \diagramfile{foo}
  74. %    {\diagramfile{baz}\diagramf{1}}
  75. %    \diagramf{2}
  76. %
  77. % You get diagram 1 from baz, and diagram 2 from foo.
  78. %
  79. % The metafont program for the diagrams contains TeX code for the
  80. % labels, which it spits out to an auxilary .dia file, of the
  81. % form
  82. %
  83. %    \newdiagramfont{example}
  84. %    \newdiagram{2}
  85. %    \diagramlabel{0}{4.88908pt}{0pt}
  86. %    $g \circ h$
  87. %    \enddiagramlabel
  88. %    \diagramchar{2}
  89. %    \endnewdiagram
  90. %
  91. % This says that the font for these diagrams is called example, and
  92. % it contains diagram number 2.  This has one label (number 0),
  93. % which should be positioned at coordinates (4.88909pt, 0pt), and whose
  94. % text is $g \circ h$.  The diagram itself is character 1 in the
  95. % font.
  96. %
  97. % When \diagramfile{example} is called, it loads in example.dia, which
  98. % sets the boxes containing the diagrams, and in turn writes out
  99. % example.dim, containing the dimensions of the lables, for example
  100. %
  101. %    wd#[2][0] := 20.3344pt#;
  102. %    ht#[2][0] := 6.94444pt#;
  103. %    dp#[2][0] := 1.94444pt#;
  104. %
  105. % This is then read by metafont, and we go round the production cycle
  106. % one more time...
  107. %
  108. % Right, that's what we're doing, let's get on with it!
  109.  
  110. % To begin with, the counters, dimensions, etc. we need.
  111.  
  112. \newwrite\dimensionsfile  % The .dim output file
  113. \newcount\diagramnumber   % The number of the diagram
  114. \newcount\labelnumber     % The number of the label
  115. \newdimen\labelxoffset    % The x-coordinate of the label
  116. \newdimen\labelyoffset    % The y-coordinate of the label
  117. \newtoks\everylabel       % Tokens put in every label (a la \everymath)
  118.  
  119.  
  120. % A handy macro for hacking around with \csname's...
  121. % \csnameafter\foo{baz} expands out to \foo\baz.
  122.  
  123. \def\csnameafter#1#2{\expandafter#1\csname#2\endcsname}
  124.  
  125. % \percent is a % mark, only with catcode 11 (i.e. a letter),
  126. % similarly \hashmark.
  127.  
  128. {\catcode`\%=11\gdef\percent{%}}
  129. {\catcode`\#=11\gdef\hashmark{#}}
  130.  
  131. % \allocatebox{foo} gets a new box \foo, if \foo is undefined.
  132.  
  133. \def\allocatebox#1%
  134.    {\@ifundefined{#1}{\csnameafter\newbox{#1}}{}}
  135.  
  136. % In order to do this, \newbox has to be non-\outer, grumble grumble
  137. % why was it ever \outer in the first place grumble grumble...
  138.  
  139. \def\newbox{\alloc@4\box\chardef\insc@unt}
  140.  
  141. % When you say \diagramfile{example} we open
  142. % example.dim for output, read in example.dia, and then close
  143. % example.dia.
  144.  
  145. \def\diagramfile#1%
  146.    {\immediate\openout\dimensionsfile #1.dim%
  147.     \immediate\write\dimensionsfile{\percent Filename: #1.dim}%
  148.     \immediate\write\dimensionsfile{\percent Generated by: diagramf.sty}%
  149.     \immediate\write\dimensionsfile{\percent Date: \today}%
  150.     \@input{#1.dia}%
  151.     \immediate\closeout\dimensionsfile
  152.     \typeout{Dimensions written on #1.dim.}}
  153.  
  154. % The first command in FONTNAME.dia should be
  155. % \newdiagramfont{FONTNAME}---this causes us to load the font in.
  156. % (Exercise for the reader: why isn't this done by \diagramfile?  Hint: if
  157. % we run LaTeX before running metafont, neither FONTNAME.dia nor
  158. % FONTNAME.tfm will exist.)
  159.  
  160. \def\newdiagramfont#1{\font\diagramfont=#1\relax}
  161.  
  162. % Then the macro that defines a diagram.  \newdiagram{N} makes us
  163. % define \diagramnumber to be N, allocate a new box \diagram-N, and
  164. % set the box to whatever comes between here and the \endnewdiagram.
  165.  
  166. \def\newdiagram#1%
  167.    {\diagramnumber=#1
  168.     \allocatebox{diagram-#1}%
  169.     \csnameafter\setbox{diagram-#1}\hbox\bgroup}
  170.  
  171. \def\endnewdiagram
  172.    {\egroup}
  173.  
  174. % Within the \newdiagram we can have commands to set labels, of the
  175. % form \diagramlabel{N}{X}{Y}...\enddiagramlabel.  To begin with, we
  176. % set \labelnumber to N, \labelxoffset to X, \labelyoffset to Y, then
  177. % set box 0 to be everything up to the \enddiagramlabel.
  178.  
  179. \def\diagramlabel#1#2#3%
  180.    {\labelnumber=#1
  181.     \labelxoffset=#2
  182.     \labelyoffset=#3
  183.     \setbox0\hbox\bgroup\the\everylabel}
  184.  
  185. % When we have set the box containing the label, we write its
  186. % dimensions on the .dim file, move the box to coordinates
  187. % (\labelxoffset, \labelyoffset), reduce it to zero size, and set it.
  188.  
  189. \def\enddiagramlabel
  190.    {\egroup
  191.     \immediate\write\dimensionsfile
  192.        {wd\hashmark[\the\diagramnumber][\the\labelnumber]
  193.             := \the\wd0\hashmark;}%
  194.     \immediate\write\dimensionsfile
  195.        {ht\hashmark[\the\diagramnumber][\the\labelnumber]
  196.             := \the\ht0\hashmark;}%
  197.     \immediate\write\dimensionsfile
  198.        {dp\hashmark[\the\diagramnumber][\the\labelnumber]
  199.             := \the\dp0\hashmark;}%
  200.     \setbox0\hbox{\kern\labelxoffset\raise\labelyoffset\box0}%
  201.     \wd0=0pt \ht0=0pt \dp0=0pt
  202.     \box0}
  203.  
  204. % The other command you can have within a diagram is \diagramchar{N}
  205. % which just causes us to set character N of \diagramfont.
  206.  
  207. \def\diagramchar#1%
  208.    {{\diagramfont\char#1\relax}}
  209.  
  210. % Finally, to set a diagram, you just say \diagramf{N} which causes us
  211. % to leave vertical mode (in the same fashion as \mbox) and set box
  212. % \diagram-N.
  213.  
  214. \def\diagramf#1%
  215.    {\leavevmode
  216.     \@ifundefined
  217.        {diagram-#1}
  218.        {??\@warning{Diagram #1 on page \thepage\space undefined}}
  219.        {\csnameafter\copy{diagram-#1}}}
  220.  
  221.  
  222.  
  223.